package com.example.thirdstage_project.common;

/**
 * @CreateTime: 2022-11-22  16:36
 * @Description: 通用结果集封装
 */
public class Result2<T> {

    private static final Integer SUCCESS = 200;

    private static final Integer FAIL = 500;

    private Integer code;

    private String message;

    private T Data;

    public Result2(Integer code) {
        this.code = code;
    }

    public Result2(Integer code, String message) {
        super();
        this.code = code;
        this.message = message;
    }

    public Result2(Integer code, String message, T data) {
        super();
        this.code = code;
        this.message = message;
        Data = data;
    }

    public Result2() {

    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return Data;
    }

    public void setData(T data) {
        Data = data;
    }

    public static <T> Result2<T> ok(T object) {
        return new Result2<T>(SUCCESS, "", object);
    }

    public static <T> Result2<T> ok() {
        return new Result2<T>(SUCCESS);
    }


    public static <T> Result2<T> ok(String msg, T object) {
        return new Result2<T>(SUCCESS,msg,object);
    }
    public static <T> Result2<T> ok(String msg){return new Result2<T>(SUCCESS);}

    public static <T> Result2<T> error(String message) {
        return new Result2<T>(FAIL, message);
    }

    public static <T> Result2<T> error() {
        return new Result2<T>(FAIL);
    }

    public static <T> Result2<T> error(String message, T object) {
        return new Result2<T>(FAIL, message, object);
    }

    public static <T> Result2<T> error(Integer code, String message) {
        return new Result2<T>(code, message);
    }

    public static <T> Result2<T> error(Integer code, String message, T object) {
        return new Result2<T>(code, message, object);
    }
}

